var _RESERVE_TABLE 					= "reserveTable";
var _RESERVE_INFO_TYPE_INDICATOR 	= "reserveInfoTypeIndicator";

var cal1_detail, over_cal_detail = false,cur_field_detail = '';
var setupListenersDetail = function() {
	YAHOO.util.Event.addListener('cal1Container', 'mouseover', function() {
        over_cal_detail = true;
    });
	YAHOO.util.Event.addListener('cal1Container', 'mouseout', function() {
        over_cal_detail = false;
    });
};

var getDateDetail = function() {
    var calDate = this.getSelectedDates()[0];
    calDate = (calDate.getDate()<10?"0":"") + calDate.getDate()
            + '/' + (calDate.getMonth()<9?"0":"") + (calDate.getMonth()+1)
            + '/' + calDate.getFullYear();
    
    cur_field_detail.value = calDate;
    over_cal_detail = false;
    hideCalDetail();
    cur_field_detail.onchange();
};
var showCalDetail = function(ev) {
    var tar = YAHOO.util.Event.getTarget(ev);
    cur_field_detail = tar;

    var xy = YAHOO.util.Dom.getXY(tar),
        date = YAHOO.util.Dom.get(tar).value;
    if(date){
        cal1_detail.cfg.setProperty('selected', date);
        //cal1.cfg.setProperty("PAGEDATE", "10/2010");
    } else{
        cal1_detail.cfg.setProperty('selected', '');
        //cal1.cfg.setProperty('pagedate', new Date(), true);
    }
    cal1_detail.render();
    YAHOO.util.Dom.setStyle('cal1Container', 'display', 'block');
    xy[1] = xy[1] + 20;
    YAHOO.util.Dom.setXY('cal1Container', xy);
};

var hideCalDetail = function() {
    if (!over_cal_detail) {
    	YAHOO.util.Dom.setStyle('cal1Container', 'display', 'none');
    }
};

function addRowReserve(colList){
	colList				= colList==null?new Array():colList;
    var	dateFrom        = colList["dateFrom"]==null?"":colList["dateFrom"];
    var	dateTo        	= colList["dateTo"]==null?"":colList["dateTo"];
    var	typeOfRoomId   	= colList["typeOfRoomId"]==null?"":colList["typeOfRoomId"];
    var	typeOfRoom      = colList["typeOfRoom"]==null?"":colList["typeOfRoom"];
    var	zone     		= colList["zone"]==null?"":colList["zone"];
    var	floor       	= colList["floor"]==null?"":colList["floor"];
    var	day       		= colList["day"]==null?"":colList["day"];
    var	qtyRoomPerDay   = colList["qtyRoomPerDay"]==null?"":colList["qtyRoomPerDay"];
    var	ratePerRoom     = colList["ratePerRoom"]==null?"0":colList["ratePerRoom"];
    var	totalAmount     = colList["totalAmount"]==null?"0":colList["totalAmount"];
    var	breakfast       = colList["breakfast"]==null?"":colList["breakfast"];
    var	errCode       	= colList["errCode"]==null?"":colList["errCode"];
    var	errMsg       	= colList["errMsg"]==null?"":colList["errMsg"];

    var tblBody         = document.getElementById(_RESERVE_TABLE);
    var size            = tblBody.rows.length;
    var newRow          = tblBody.insertRow(-1);
    newRow.height       = "30px";
    newRow.className	= "tBody";

    //TypeOfRoom
    var tdTypeOfRoom    = document.getElementById("templateTypeOfRoom");
    var tmpTypeOfRoom   = document.getElementsByName("colTypeOfRoomId");
    var len				= tmpTypeOfRoom.length;     
    if(len){
    	tmpTypeOfRoom[len-1].value	= typeOfRoomId;
    }else{
    	tmpTypeOfRoom.value      	= typeOfRoomId;
    }
    
    var newCell;
    var rowIndex        = 0;
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<a onclick="delRowReserve(this)"><img src="./images/calendar/close.gif" /></a>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = size+1;
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colDateFrom" size="10" maxlength="10" value="'+dateFrom+'" onchange="setDetailIndex(this);validateColDateFrom()" class="iNL"/>' +
    					  '&nbsp;<img style="cursor:hand" src="./images/calendar.gif" onclick="this.parentElement.childNodes(0).click();"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colDateTo" size="10" maxlength="10" value="'+dateTo+'" onchange="setDetailIndex(this);validateColDateTo()" class="iNL"/>' +
	  					  '&nbsp;<img style="cursor:hand" src="./images/calendar.gif" onclick="this.parentElement.childNodes(0).click();"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = tdTypeOfRoom.innerHTML;
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<select name="colZone" onchange="setDetailIndex(this);validateColZone()"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<select name="colFloor" onchange="setDetailIndex(this);validateColFloor()"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colDay" size="5" maxlength="5" value="'+day+'" readonly class="iDL"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colQtyRoomPerDay" size="5" maxlength="3" value="'+qtyRoomPerDay+'" onchange="setDetailIndex(this);validateColQtyRoomPerDay()" onkeypress="return text_OnKeyPress_NumberOnly();" class="iNL"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colRatePerRoom" size="10" maxlength="8" value="'+ratePerRoom+'" onchange="setDetailIndex(this);validateColRatePerRoom()" onkeypress="return text_OnKeyPress_NumberOnlyAndDot();" class="iNR"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    newCell.innerHTML   = '<input type="text" name="colTotalAmount" size="10" maxlength="8" value="'+totalAmount+'" readonly class="iDR"/>';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    var chk				= breakfast=='1'?'checked':'';
    newCell.innerHTML   = '<input type="checkbox" name="colBreakfastTmp" value="1" ' + chk + ' onclick="setDetailIndex(this);validateColBreakfast()" />';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("align","center");
    var errRoomRate		= document.getElementById("msgErrorManyRoom").innerText + ' ' + errMsg;
    newCell.innerHTML   = errMsg!=""?'<b><font color="red" title="'+errRoomRate+'">X</font></b>':'';
    
    newCell             = newRow.insertCell(rowIndex++);
    newCell.setAttribute("display", "none");
    newCell.innerHTML   = '<input type="hidden" name="colTypeOfRoom" />' +
    					  '<input type="hidden" name="colBreakfast" value="' + breakfast + '"/>';
    
    var typeOfRoomObj		= document.getElementsByName("colTypeOfRoomId")[size];
    var typeOfRoomNameObj	= document.getElementsByName("colTypeOfRoom")[size];
    typeOfRoomNameObj.value	= typeOfRoomObj.options[typeOfRoomObj.selectedIndex].text;
    createZoneCombo(typeOfRoomObj.options[typeOfRoomObj.selectedIndex].value, size);
    if(zone != ""){
    	document.getElementsByName("colZone")[size].value = zone;
    }
    if(floor != ""){
    	document.getElementsByName("colFloor")[size].value = floor;
    }
    
    _ROW_INDEX = size;
    
    cal1_detail = new YAHOO.widget.Calendar("cal1_detail", "cal1Container");
    cal1_detail.cfg.setProperty("MDY_DAY_POSITION", 1);
    cal1_detail.cfg.setProperty("MDY_MONTH_POSITION", 2);
    cal1_detail.cfg.setProperty("MDY_YEAR_POSITION", 3);
    cal1_detail.selectEvent.subscribe(getDateDetail, cal1_detail, true);
    cal1_detail.renderEvent.subscribe(setupListenersDetail, cal1_detail, true);
    
    YAHOO.util.Event.addListener(document.getElementsByName("colDateFrom")[size], 'click', showCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateFrom")[size], 'blur', hideCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateTo")[size], 'click', showCalDetail);
    YAHOO.util.Event.addListener(document.getElementsByName("colDateTo")[size], 'blur', hideCalDetail);
}

function delRowReserve(obj){
    var rowIndex        = obj.parentElement.parentElement.rowIndex-1;
    
    var tblBody         = document.getElementById(_RESERVE_TABLE);
    if(confirm('Do you want to delete?')){
        tblBody.deleteRow(rowIndex);
        
        calculateAllTotalAmount();
    }
}

function addRowAvailable(typeOfRoom, dateGen, price){
	colList					= new Array();
    colList["dateFrom"]		= dateGen;
    colList["dateTo"]		= genNextDay(dateGen, 1);
    colList["typeOfRoomId"]	= typeOfRoom;
    var _day				= calculateBetweenDate(dateGen, dateGen)+1;
    colList["day"]			= _day;
    colList["qtyRoomPerDay"]= 1;
    colList["ratePerRoom"]	= price;
    var _price				= price==''?0:parseFloat(removeCommas(price));
    var _total				= _price * 1 * _day;
    colList["totalAmount"]	= tryNumberFormatValue(_total, true, 2);
    
    addRowReserve(colList);
    
    calculateTotalAmount();
}

var rowIndexTmp;
function createZoneCombo(typeOfRoom, rowIndex){
	rowIndexTmp		= rowIndex;
    var params		= "subTypeOfRoom=" + typeOfRoom;

    //clear combo
    var colZone		= document.getElementsByName("colZone")[rowIndex];		
    var colFloor	= document.getElementsByName("colFloor")[rowIndex];		
    colZone.options.length 	= 0;
    colFloor.options.length = 0;
    var isIE 		= detect_browser();
    var newOption 	= window.document.createElement("option");
    newOption.value = "";
    newOption.text 	= "All";
    if(isIE==true)
    	colZone.add(newOption);
    else
    	colZone.appendChild(newOption); 
    newOption 	= window.document.createElement("option");
    newOption.value = "";
    newOption.text 	= "All";
    if(isIE==true)
    	colFloor.add(newOption);
    else
    	colFloor.appendChild(newOption); 
    
    document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "inline";
    isdnSendRequest("reserveInfoType_getZoneListJSON.action", params , "POST", callbackCreateZoneCombo);
}

callbackCreateZoneCombo = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data['com.appsindy.reserv.bo.Combo']){            	
                var detail  = jsonObject.object.data['com.appsindy.reserv.bo.Combo'];
                var size 	= detail.length;
                var isIE 	= detect_browser();
                var colZone = document.getElementsByName("colZone")[rowIndexTmp];
                if(size){
                	for(var i = 0; i < size; i ++) {
	                    var newOption 	= window.document.createElement("option");
	                    newOption.value = detail[i].key;
	                    newOption.text 	= detail[i].key;
	                    if(isIE==true)
	                    	colZone.add(newOption);
	                    else
	                    	colZone.appendChild(newOption); 
                	}
                }else{
                    var newOption 	= window.document.createElement("option");
                    newOption.value = detail.key;
                    newOption.text 	= detail.key;
                    if(isIE==true)
                    	colZone.add(newOption);
                    else
                    	colZone.appendChild(newOption);                	
                }
                var typeOfRoomObj	= document.getElementsByName("colTypeOfRoomId")[rowIndexTmp]; 
                var zoneObj			= document.getElementsByName("colZone")[rowIndexTmp]; 
                createFloorCombo(typeOfRoomObj.options[typeOfRoomObj.selectedIndex].value, zoneObj.options[zoneObj.selectedIndex].value, rowIndexTmp);
            }
            
            document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "none";
        }
    }
};
function createFloorCombo(typeOfRoom, zone, rowIndex){
	rowIndexTmp		= rowIndex;
    var params		= "subTypeOfRoom=" + typeOfRoom + "&subZone=" + zone;

    //clear combo
    var colFloor 	= document.getElementsByName("colFloor")[rowIndex];
    colFloor.options.length = 0;
    var isIE 		= detect_browser();
    var newOption 	= window.document.createElement("option");
    newOption.value = "";
    newOption.text 	= "All";
    if(isIE==true)
    	colFloor.add(newOption);
    else
    	colFloor.appendChild(newOption); 

    document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "inline";
    isdnSendRequest("reserveInfoType_getFloorListJSON.action", params , "POST", callbackCreateFloorCombo);
}

callbackCreateFloorCombo = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );

            if(jsonObject.object.data['com.appsindy.reserv.bo.Combo']){            	
                var detail  = jsonObject.object.data['com.appsindy.reserv.bo.Combo'];
                var size 	= detail.length;
                var isIE 	= detect_browser();
                var colFloor= document.getElementsByName("colFloor")[rowIndexTmp];
                if(size){
                	for(var i = 0; i < size; i ++) {
	                    var newOption 	= window.document.createElement("option");
	                    newOption.value = detail[i].key;
	                    newOption.text 	= detail[i].key;
	                    if(isIE==true)
	                    	colFloor.add(newOption);
	                    else
	                    	colFloor.appendChild(newOption); 
                	}
                }else{
                    var newOption 	= window.document.createElement("option");
                    newOption.value = detail.key;
                    newOption.text 	= detail.key;
                    if(isIE==true)
                    	colFloor.add(newOption);
                    else
                    	colFloor.appendChild(newOption);                	
                }
            }
            document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "none";
        }
    }
};

var _ROW_INDEX = 0;
function setDetailIndex(obj){	
    if(obj){
    	var rowIndex = obj.parentElement.parentElement.rowIndex-1;
    	_ROW_INDEX   = rowIndex;
    }	
}

function validateColDateFrom(){
	var dateFrom 	= document.getElementsByName("colDateFrom")[_ROW_INDEX];
	var dateTo 		= document.getElementsByName("colDateTo")[_ROW_INDEX];
	var day 		= document.getElementsByName("colDay")[_ROW_INDEX];
	
	if(validateDateFormat(dateFrom)){	
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateFrom less than dateTo.");
				dateFrom.value = "";
				dateFrom.focus();
			}else{
				day.value	= _day;
				getRoomRate();
				calculateTotalAmount();
			}
	}
	}
}
function validateColDateTo(){	
	var dateFrom 	= document.getElementsByName("colDateFrom")[_ROW_INDEX];
	var dateTo 		= document.getElementsByName("colDateTo")[_ROW_INDEX];
	var day 		= document.getElementsByName("colDay")[_ROW_INDEX];
	
	if(validateDateFormat(dateTo)){	
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateTo more than than dateFrom.");
				dateTo.value = "";
				dateTo.focus();
			}else{
				day.value	= _day;
				getRoomRate();
				calculateTotalAmount();
			}	
		}
	}
}
function validateColTypeOfRoom(){
	var typeOfRoomObj		= document.getElementsByName("colTypeOfRoomId")[_ROW_INDEX];
	var typeOfRoomNameObj 	= document.getElementsByName("colTypeOfRoom")[_ROW_INDEX];
	
	typeOfRoomNameObj.value	= typeOfRoomObj.options[typeOfRoomObj.selectedIndex].text;
	
	createZoneCombo(typeOfRoomObj.value, _ROW_INDEX);	
	
	getRoomRate();
	calculateTotalAmount();
}
function validateColZone(){
	var typeOfRoomObj 		= document.getElementsByName("colTypeOfRoomId")[_ROW_INDEX];
	var zoneObj				= document.getElementsByName("colZone")[_ROW_INDEX];
	createFloorCombo(typeOfRoomObj.value, zoneObj.value, _ROW_INDEX);	
}
function validateColFloor(){
}
function validateColQtyRoomPerDay(){
	var obj		= document.getElementsByName("colQtyRoomPerDay")[_ROW_INDEX];
    var val		= obj.value==''?0:parseFloat(removeCommas(obj.value));
    obj.value	= tryNumberFormatValue(val, true, 0);
    
	calculateTotalAmount();
}
function validateColRatePerRoom(){	
	var obj		= document.getElementsByName("colRatePerRoom")[_ROW_INDEX];
    var val		= obj.value==''?0:parseFloat(removeCommas(obj.value));
    obj.value	= tryNumberFormatValue(val, true, 2);	
    
	calculateTotalAmount();
}
function validateColBreakfast(){	
	var colBreakfastTmp = document.getElementsByName("colBreakfastTmp")[_ROW_INDEX];
	if(colBreakfastTmp.checked){
		document.getElementsByName("colBreakfast")[_ROW_INDEX].value = "1";
	}
}
function calculateTotalAmount(){
	var colDayObj 			= document.getElementsByName("colDay")[_ROW_INDEX];
	var colQtyRoomPerDay 	= document.getElementsByName("colQtyRoomPerDay")[_ROW_INDEX];
	var colRatePerRoom 		= document.getElementsByName("colRatePerRoom")[_ROW_INDEX];
	var colTotalAmount 		= document.getElementsByName("colTotalAmount")[_ROW_INDEX];
	
	var calDay				= colDayObj.value==''?0:parseFloat(removeCommas(colDayObj.value));
	var calQty				= colQtyRoomPerDay.value==''?0:parseFloat(removeCommas(colQtyRoomPerDay.value));
	var calRate				= colRatePerRoom.value==''?0:parseFloat(removeCommas(colRatePerRoom.value));
	var calTotal			= calRate * calQty * calDay;
	
	
	colTotalAmount.value	= tryNumberFormatValue(calTotal, true, 2);
	
	calculateAllTotalAmount();
}

function calculateAllTotalAmount(){
	var grandTotalAmount 	= document.getElementById("grandTotalAmount");
	//calculate all totalAmount
    var tblBody             = document.getElementById(_RESERVE_TABLE);
    var size                = tblBody.rows.length;
    var total				= 0;
    for(var i=0; i<size; i++){
    	var totalObj 		= document.getElementsByName("colTotalAmount")[i];
    	total			   += totalObj.value==''?0:parseFloat(removeCommas(totalObj.value));
    }
	grandTotalAmount.innerText	= tryNumberFormatValue(total, true, 2);	
}

function getRoomRate(){
	var groupId		= document.getElementById("groupId");
	var dateFrom	= document.getElementsByName("colDateFrom")[_ROW_INDEX];
	var dateTo		= document.getElementsByName("colDateTo")[_ROW_INDEX];
	var typeOfRoom	= document.getElementsByName("colTypeOfRoomId")[_ROW_INDEX];
	
	if(dateFrom.value == ""){
		return false;
	}else if(dateTo.value == ""){
		return false;
	}else if(typeOfRoom.value == ""){
		return false;
	}
    var params		= "subGroupId=" + groupId.value + "&subDateFrom=" + dateFrom.value + "&subDateTo=" + dateTo.value;
    params		   += "&subTypeOfRoom=" + typeOfRoom.value;
    
    document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "inline";
    isdnSendRequest("reserveInfoType_getRoomRateJSON.action", params , "POST", callbackGetRoomRate);
}

callbackGetRoomRate = function() {
    var ready = req.readyState;
    //  console.debug(ready);
    var jsonObject=null;
    if ( ready == 4 ){
        if(req.status == 200) {
            jsonObject=eval( "("+ req.responseText +")" );
            
			var colRatePerRoom 		= document.getElementsByName("colRatePerRoom")[_ROW_INDEX];
			var colDateFrom	 		= document.getElementsByName("colDateFrom")[_ROW_INDEX];
			var colDateTo	 		= document.getElementsByName("colDateTo")[_ROW_INDEX];
			var colDay	 			= document.getElementsByName("colDay")[_ROW_INDEX];
			var colQtyRoomPerDay	= document.getElementsByName("colQtyRoomPerDay")[_ROW_INDEX];
            if(jsonObject.object.data.errCode < 0){
            	alert(jsonObject.object.data.errMsg);
            	colDateTo.value		= genNextDay(colDateFrom.value, 1);
            	colDay.value		= 1;
            }
            
            if(jsonObject.object.data.ratePerRoom){
            	colRatePerRoom.value	= jsonObject.object.data.ratePerRoom;
            }else{
            	colRatePerRoom.value	= 0.00;
            }
			if(colQtyRoomPerDay.value == ""){
				colQtyRoomPerDay.value	= 1;	//default 1
			}

            document.getElementById(_RESERVE_INFO_TYPE_INDICATOR).style.display = "none";
        }
    }
};

dojo.event.topic.subscribe("/beforeSearchTypeOfRoom", function(event, widget){
    try{
		var dateFrom 	= document.getElementById("dateFromInfoType");
		var dateTo 		= document.getElementById("dateToInfoType");
		
		if(dateFrom.value == ""){
			alert("Please input dateFrom");
			dateFrom.focus();
			event.cancel = true;
		}else if(dateTo.value == ""){
			alert("Please input dateTo");
			dateTo.focus();
			event.cancel = true;
		}
    }catch(err ) {
         alert("Javascript error in this reserve info page beforeSearchTypeOfRoom main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});
dojo.event.topic.subscribe("/beforeBack", function(event, widget){
    try{
    	var msg = document.getElementById("msgConfirmBack").innerText;
        if(!confirm(msg)){
        	event.cancel = true;
        }

    }catch(err ) {
         alert("Javascript error in this reserve info page beforeBack main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});
function btnInfoTypeBackOnClick(obj){
	var msg = document.getElementById("msgConfirmBack").innerText;
    if(confirm(msg)){
        url = "reserveInfoType_back.action";
        document.getElementById("frmReserveInfoType").action = url;
        document.getElementById("frmReserveInfoType").submit();
        return true;
    }
    return false;
}
dojo.event.topic.subscribe("/beforeSkip", function(event, widget){
    try{
    	var msg = document.getElementById("msgConfirmSkip").innerText;
        if(!confirm(msg)){
        	event.cancel = true;
        }

    }catch(err ) {
         alert("Javascript error in this reserve info page beforeSkip main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});


function validateDateFromInfoType(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromInfoType");
		var dateTo 		= document.getElementById("dateToInfoType");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateFrom less than dateTo.");
				dateFrom.value = "";
				dateFrom.focus();
			}
		}		
	}
}
function validateDateToInfoType(obj) {
	if(validateDateFormat(obj)){
		var dateFrom 	= document.getElementById("dateFromInfoType");
		var dateTo 		= document.getElementById("dateToInfoType");
		
		if(dateFrom.value != "" && dateTo.value != ""){
			var _day		= calculateBetweenDate(dateFrom.value, dateTo.value);
			if(_day <= 0){
				alert("Please input dateTo more than dateFrom.");
				dateTo.value = "";
				dateTo.focus();
			}
		}
	}
}

dojo.event.topic.subscribe("/beforeInfoTypeReserveClick", function(event, widget){
    try{
        var tblBody = document.getElementById(_RESERVE_TABLE);
        var size	= tblBody.rows.length;
        
    	var msg 	= document.getElementById("msgQtyMorethanZero").innerText;
    	
    	var arrDateFrom	= document.getElementsByName("colDateFrom");
    	var arrDateTo	= document.getElementsByName("colDateTo");
    	var arrQty		= document.getElementsByName("colQtyRoomPerDay");
    	
    	if(size > 0){
    		var isFail = false;
    		for(var i=0; i<size; i++){
    			if(arrDateFrom[i].value == ''){
        			alert("Please input date from.");
        			arrDateFrom[i].focus();
        			isFail = true;    				
    			}else if(arrDateTo[i].value == ''){
        			alert("Please input date to.");
        			arrDateTo[i].focus();
        			isFail = true;    				
    			}else if(arrQty[i].value == ''){
        			alert("Please input qty room per day.");
        			arrQty[i].focus();
        			isFail = true;    				
    			}else if(arrQty[i].value != '' && parseInt(arrQty[i].value) <= 0){
        			alert(msg);
        			arrQty[i].focus();
        			isFail = true;
    			}
    		}
    		if(isFail){
            	event.cancel = true;
    		}
    	}

    }catch(err ) {
         alert("Javascript error in this reserve info page beforeInfoTypeReserveClick main function() [Error: " + err.message + "]");
         event.cancel = true;
    }
});


function onMouseOverAvailable(){
	var _td = event.srcElement;
	_td.className = "tdMouseOver";
	document.getElementById("tdStatus").innerHTML = "Please double click for select this Room (and prices).";
}
function onMouseOutAvailable(){
	var _td = event.srcElement;
	_td.className = "tdMouseOut";
	document.getElementById("tdStatus").innerHTML = "&nbsp;";
}
